package com.wgy.day15.String字符串类;

/**
 * Created by pc on 2020/11/10 21:26
 * Description: LearningJava
 */
public class Demo07StringSplit {

    /*字符串的分割方法
    public String[] split(String regex):按照参数的规则,将字符串切分成若干部分.()里面的内容就是切割的规则 返回的是一个String[] array
    注意:当要按照英文句点"."来进行切分的时候,小括号内的写法要换成是"\\."(即多了两个反斜杠)
    */


    public static void main(String[] args) {
        String str1 = "aaa,bbb,ccc";
        String[] array = str1.split(",");
        System.out.println(array[0]);  //aaa
        System.out.println(array[1]);  //bbb
        System.out.println(array[2]);  //ccc
        System.out.println("=============");

        String str2 = "aaa bbb ccc";
        String[] array1 = str2.split(" ");
        for (int i = 0; i < array.length; i++) {
            System.out.println(array1[i]);

        }
        System.out.println("=============");

        String str3 = "aaa.bbb.ccc";
        //    String [] array3=str3.split(".");   错误写法  当里面是英文句点的时候小括号内的写法要换成是\\.
        String[] array3 = str3.split("\\.");
        for (int i = 0; i < array.length; i++) {
            System.out.println(array3[i]);

        }


    }
}
